package com.just.sxmiaosha.controller;


import com.google.common.util.concurrent.RateLimiter;
import com.just.sxmiaosha.service.StockOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author just
 * @since 2020-09-23
 */
@RestController
@RequestMapping("/order")
public class StockOrderController {

    @Autowired
    private StockOrderService orderService;


    @PostMapping("/createWrongOrder")
    public String createWrongOrder(int sid, int count) {
        String id = orderService.createWrongOrder(sid, count);
        return id;
    }

    /**
     * 乐观锁
     *
     * @param sid
     * @param count
     * @return
     */
    @PostMapping("/createOptimisticOrder")
    public String createOptimisticOrder(int sid, int count) {
        return orderService.createOptimisticOrder(sid, count);
    }

    /**
     * 悲观锁
     */
    @PostMapping("/createPessimisticOrder")
    public String createPessimisticOrder(int sid, int count) {
        return orderService.createPessimisticOrder(sid, count);
    }

    /**
     * 获取验证接口
     */
    @PostMapping("/getVerifyHash")
    public String getVerifyHash(int sid, int count, int userId) {

        return orderService.getVerifyHash(sid, count, userId);
    }

    @PostMapping("/createOrderWithVerifiedUrl")
    public String createOrderWithVerifiedUrl(int sid, int count, int userId, String verifyHash) {
        return orderService.createVerifiedOrder(sid, count, userId, verifyHash);
    }

    @PostMapping("/createOrderWithVerifiedUrlAndLimit")
    public String createOrderWithVerifiedUrlAndLimit(int sid, int count, int userId, String verifyHash) {
        return orderService.createOrderWithVerifiedUrlAndLimit(sid, count, userId, verifyHash);

    }

    @PostMapping("/createOrderWithCacheV1")
    public String createOrderWithCacheV1(int sid, int count) {
        return orderService.createOrderWithCacheV1(sid, count);
    }

    @PostMapping("/createOrderWithCacheV2")
    public String createOrderWithCacheV2(int sid, int count) {
        return orderService.createOrderWithCacheV2(sid, count);
    }

    @PostMapping("/createOrderWithCacheV3")
    public String createOrderWithCacheV3(int sid, int count) {
        return orderService.createOrderWithCacheV3(sid, count);
    }

    @PostMapping("/createOrderWithMq")
    public String createOrderWithMq(int sid, int count){
       return orderService.createOrderWithMq(sid,count);
    }
}
